/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.tesoreria.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import org.cip.esymons.general.util.ControladorAbstracto;
import org.cip.esymons.tesoreria.be.ConfiguracionOtros;
import org.cip.esymons.tesoreria.beans.ConfiguracionOtrosController;

/**
 *
 * @author Gilmar
 */
public class ConfiguracionOtrosConverter implements Converter{

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String value) throws ConverterException {
        if (value == null) {
            return null;
        }

        try {
            Integer id = Integer.decode(value.toString());
            ConfiguracionOtrosController controller = (ConfiguracionOtrosController) ControladorAbstracto.getBean("configuracionOtrosController");
            ConfiguracionOtros cb = controller.buscarPorCodigo(id);
            return cb;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object object) throws ConverterException {
        if (object == null) {
            return null;
        }
        if (object instanceof ConfiguracionOtros) {
            ConfiguracionOtros ba = (ConfiguracionOtros) object;
            return "" + ba.getConCodigo();
        } else {
            return null;
        }
    }

}
